<template>
	<view class="container">
		<uni-forms ref="form" :modelValue="formData">
			<image class="logo" src="/static/uni.png"></image>
			<view class="form-group" name="username">
				<image class="icon" src="/static/image/账户名.png"></image>
				<input class="input" v-model="username" type="text" placeholder="请输入用户名" bindinput="inputUsername" />
			</view>
			<view class="form-group" name="password">
				<image class="icon" src="/static/image/密码.png"></image>
				<input class="input" v-model="password" type="password" placeholder="请输入密码" bindinput="inputPassword" />
			</view>
		</uni-forms>
		<button class="btn-login" @click="login" bindtap="login">登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username:"张三" ,
				password:"123",
			}
		},
		methods: {
			login() {
				console.log(this.password)
				uni.request({
					url:"login",
					data: {
						"username":this.username + "-owner",
						"password":this.password
					},
					method: "POST",
					header:{
						"Content-Type":'application/x-www-form-urlencoded'
					},
					success:(res) => {
						uni.setStorageSync("token",res.data.data)
						uni.setStorageSync("username",this.username+ "-owner")
						console.log(res.data)
						if(res.data.code == 200){
							uni.switchTab({
								url: "/pages/list/list"
							});
						}else{
							uni.switchTab({
								url: "/pages/login/login"
							});
						}
					}
				})
			}
		}
	}
</script>

<style>
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		height: 100vh;
		background: linear-gradient(135deg, #3A9FFC 0%, #8B86E0 100%);
	}

	.logo {
		width: 200px;
		height: 200px;
		margin-bottom: 40px;
		position: relative;
		left: 60px;
	}

	.form-group {
		display: flex;
		align-items: center;
		width: 300px;
		height: 60px;
		margin-bottom: 20px;
		background-color: #fff;
		border-radius: 30px;
		padding: 0 20px;
	}

	.icon {
		width: 30px;
		height: 30px;
		margin-right: 10px;
	}

	.input {
		flex: 1;
		height: 100%;
		background-color: transparent;
		outline: none;
		border: none;
		font-size: 28px;
		color: #333;
	}

	.btn-login {
		width: 300px;
		height: 60px;
		line-height: 60px;
		text-align: center;
		background-color: #fff;
		color: #3A9FFC;
		border-radius: 30px;
		font-size: 32px;
	}
</style>